<html>
<head><meta charset="utf-8"><title>Rust-based JIT · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html">Rust-based JIT</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="211004513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211004513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hameer Abbasi <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211004513">(Sep 23 2020 at 13:44)</a>:</h4>
<p>I know Rust as a language has decided not to have a runtime, but I'm stuck between a rock and a hard place where I have "infinite types" due to generics, so generating them at runtime is absolutely essential. I could refactor to do runtime dispatch, but then the performance of the code will absolutely die due to the overhead (some of them will just be adding an element to a <code>Vec</code>). Does Rust or any crate have a way to do something like this in an idiomatic manner?</p>



<a name="211008072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211008072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211008072">(Sep 23 2020 at 14:07)</a>:</h4>
<blockquote>
<p>I have "infinite types" due to generics</p>
</blockquote>
<p>What do you mean with this. What is exactly what you want to do.</p>



<a name="211009441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211009441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hameer Abbasi <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211009441">(Sep 23 2020 at 14:15)</a>:</h4>
<p>So, I want to have a type that is generic over a <code>Tuple&lt;_,  ...&gt;</code> where all of the <code>_</code>s possess some trait. In addition, some of the methods in that trait will be as simple as <code>vec.push(...)</code> or <code>hash_map.insert(...)</code>. As you can imagine, there will be a lot of these types.</p>
<p>What I could do to work around this is use <code>dyn Trait</code> but this will kill the performance if it's something like a simple vector access or similar.</p>
<p>I could point you to the research paper I'm trying to implement if you're interested.</p>



<a name="211009513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211009513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211009513">(Sep 23 2020 at 14:16)</a>:</h4>
<p>take a look at <a href="https://docs.rs/frunk/0.3.1/frunk/">https://docs.rs/frunk/0.3.1/frunk/</a> maybe</p>



<a name="211009602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211009602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211009602">(Sep 23 2020 at 14:16)</a>:</h4>
<p>especially <a href="https://docs.rs/frunk/0.3.1/frunk/hlist/index.html">https://docs.rs/frunk/0.3.1/frunk/hlist/index.html</a></p>



<a name="211010716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211010716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hameer Abbasi <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211010716">(Sep 23 2020 at 14:25)</a>:</h4>
<p>I see. I'll have to bench the perf against something native. :) But I have the feeling it'll be substantially worse.</p>



<a name="211010851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211010851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211010851">(Sep 23 2020 at 14:26)</a>:</h4>
<p>note that dyn trait can actually be pretty fast in practice, and can even be <em>faster</em> than generics</p>



<a name="211010858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211010858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211010858">(Sep 23 2020 at 14:26)</a>:</h4>
<p>so definitely benchmark</p>



<a name="211011257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211011257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211011257">(Sep 23 2020 at 14:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/Looking.20for.20a.20Rust-based.20JIT/near/211010851">said</a>:</p>
<blockquote>
<p>note that dyn trait can actually be pretty fast in practice, and can even be <em>faster</em> than generics</p>
</blockquote>
<p><a href="https://gankra.github.io/blah/swift-abi/">https://gankra.github.io/blah/swift-abi/</a></p>



<a name="211011340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211011340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211011340">(Sep 23 2020 at 14:29)</a>:</h4>
<p>at some point I want to test the perf difference of making <em>all</em> traits <code>dyn</code></p>



<a name="211011393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211011393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211011393">(Sep 23 2020 at 14:30)</a>:</h4>
<p>not sure how or if it's feasible though</p>



<a name="211011743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211011743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211011743">(Sep 23 2020 at 14:32)</a>:</h4>
<p>It is not feasible to make traits with associated types generic. You would need to run the full layout code at runtime for that.</p>



<a name="211011815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211011815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211011815">(Sep 23 2020 at 14:33)</a>:</h4>
<p>sure, or anything taking <code>Self</code> by value</p>



<a name="211011850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211011850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211011850">(Sep 23 2020 at 14:33)</a>:</h4>
<p>but most everything else could be turned into <code>dyn</code> under the hood I think</p>



<a name="211012301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211012301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211012301">(Sep 23 2020 at 14:36)</a>:</h4>
<p>does rust guarentee <code>fn f&lt;T&gt;(t: &amp;T)</code> is monomorphized at the language level btw? or is that just how it's implemented?</p>



<a name="211012730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211012730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211012730">(Sep 23 2020 at 14:39)</a>:</h4>
<p>I don't think that is guaranteed. We guarantee nothing about function pointer comparisons at least. LLVM is told that it is fine to merge or duplicate functions using <code>unnamed_addr</code>.</p>



<a name="211025942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211025942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hameer Abbasi <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211025942">(Sep 23 2020 at 16:13)</a>:</h4>
<p>Yeah, so it's slower but not massively. About 26%. I can send over the full code for someone that needs it. This is for a simple dispatched <code>vec.push</code>. Generics are probably inlined so they're exactly the same as a <code>vec.push</code>.</p>



<a name="211075012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211075012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211075012">(Sep 23 2020 at 23:40)</a>:</h4>
<blockquote>
<p>I know Rust as a language has decided not to have a runtime</p>
</blockquote>
<p>Just to be precise, it <em>does</em> <a href="https://doc.rust-lang.org/reference/runtime.html">have a runtime</a>, it's just small and embedded in your binary</p>



<a name="211075867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211075867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211075867">(Sep 23 2020 at 23:55)</a>:</h4>
<p>in the same sense that C has a runtime, yeah</p>



<a name="211103034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Rust-based%20JIT/near/211103034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hameer Abbasi <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Rust-based.20JIT.html#211103034">(Sep 24 2020 at 08:40)</a>:</h4>
<p>Yeah, when I said "runtime" I meant non-embedded.</p>
<p>Also, for a vector access, the results are bad. 179% slowdown.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>